#include "My_ADC.h"

static const char *TAG = "ADC.CPP";


My_ADC::My_ADC(adc1_channel_t channel, 
                     adc_bits_width_t width,
                     adc_atten_t    atten)
{
    _channel = channel;
    _width = width;
    _atten = atten;

    adc1_config_width(_width);
    adc1_config_channel_atten(_channel, _atten);

}


void My_ADC::get_voltage()
{
    read_raw = adc1_get_raw(_channel);//采集ADC
    Voltage = (read_raw*2500)/4095;

    if (Voltage < 800) Level = 1;
    else if (Voltage >1800) Level = 3;
    else Level = 2;

    if(read_raw < 1500) Value_Level = 1;
    else if(read_raw < 2500) Value_Level = 2;
    else if(read_raw < 3600) Value_Level = 3;
    else Value_Level = 4;
    printf("Read Raw : %d\r\n",read_raw);
    printf("Value Level : %d\r\n",Value_Level);
	//ADC的结果转换成电压
	//参考电压是2.2V，所以是2200mV，12位分辨率，所以是4096
	// ESP_LOGI(TAG,"ADV_Value:  %d    Voltage:  %d mV \r\n", read_raw, (read_raw*2200)/4096);
    // printf("ADV_Value:  %d    Voltage:  %d mV \r\n", read_raw, voltage);
}
